package com.ziven.common.widget.value;

import android.view.View;

import androidx.annotation.NonNull;

import com.ziven.easygo.util.BiCarry;
import com.ziven.easygo.util.EasyUtils;
import com.ziven.easygo.util.ViewHelper;

import java.util.List;

/**
 * @author Ziven
 */
public final class BiValue extends MixValue {

    public static BiValue values(@NonNull Value first,
                                 @NonNull Value second) {
        return new BiValue(first, second);
    }

    private BiValue(@NonNull Value first,
                    @NonNull Value second) {
        super(first, second);
    }

    public <FIRST, SECOND> void contains(@NonNull Class<FIRST> firstClass,
                                         @NonNull Class<SECOND> secondClass,
                                         @NonNull BiCarry<FIRST, SECOND> biCarry) {
        List<Value> list = obtain();
        if(EasyUtils.instanceOf(list.get(0).value, firstClass)
                && EasyUtils.instanceOf(list.get(1).value, secondClass)) {
            biCarry.carry(
                    EasyUtils.transition(list.get(0).value),
                    EasyUtils.transition(list.get(1).value)
            );
        }
    }

    public <FIRST, SECOND> void values(@NonNull Class<FIRST> firstClass,
                                       @NonNull Class<SECOND> secondClass,
                                       @NonNull BiCarry<FIRST, SECOND> biCarry) {
        List<Value> list = obtain();
        if(EasyUtils.instanceOf(list.get(0), firstClass)
                && EasyUtils.instanceOf(list.get(1), secondClass)) {
            biCarry.carry(
                    EasyUtils.transition(list.get(0)),
                    EasyUtils.transition(list.get(1))
            );
        }
    }

    public <FIRST, SECOND> void containValue(@NonNull Class<FIRST> firstClass,
                                             @NonNull Class<SECOND> secondClass,
                                             @NonNull BiCarry<FIRST, SECOND> biCarry) {
        List<Value> list = obtain();
        if(EasyUtils.instanceOf(list.get(0).value, firstClass)
                && EasyUtils.instanceOf(list.get(1), secondClass)) {
            biCarry.carry(
                    EasyUtils.transition(list.get(0).value),
                    EasyUtils.transition(list.get(1))
            );
        }
    }

    public <FIRST, SECOND> void valueContain(@NonNull Class<FIRST> firstClass,
                                             @NonNull Class<SECOND> secondClass,
                                             @NonNull BiCarry<FIRST, SECOND> biCarry) {
        List<Value> list = obtain();
        if(EasyUtils.instanceOf(list.get(0), firstClass)
                && EasyUtils.instanceOf(list.get(1).value, secondClass)) {
            biCarry.carry(
                    EasyUtils.transition(list.get(0)),
                    EasyUtils.transition(list.get(1).value)
            );
        }
    }

    public Value first() {
        List<Value> list = obtain();
        return list.get(0);
    }

    public Value second() {
        List<Value> list = obtain();
        return list.get(1);
    }

    @Override
    protected void takeEffect(@NonNull ViewHelper<? extends View> helper, @NonNull Value[] values) {
        //Do nothing
    }
}
